@extends('public.dashboard_base')
@section('title', '添加个人认证')

@section('content')
    @php
        $user =auth('admin')->user();
    @endphp
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>账户管理</li>
                <li>我的认证</li>
                <li>添加个人认证</li>
            </ul>
        </div>
        <div class="panel">
            <div class="sub_nav_container">
                <ul class="clearfix">
                    <li><a href="/account/auth/personal">个人认证</a></li>
                    <li class="active"><a href="/account/auth/personal/add">添加个人认证</a></li>
                </ul>
            </div>
            <div class="panel_body">
                <form id="form" enctype="multipart/form-data" method="post">
                    {{csrf_field()}}
                    <ul class="form_group">
                        <li><span class="form_label">姓名</span><input type="text" name="name"></li>
                        <li>
                            <span class="form_label">证件类型</span>
                            <select name="type" style="width:280px">
                                <option value="1">身份证</option>
                                <option value="2">护照</option>
                                <option value="3">港澳居民来往内地通行证</option>
                                <option value="4">台湾居民来往大陆通行证</option>
                                <option value="5">外国人永久居留身份证</option>
                                <option value="6">港澳居民居住证</option>
                                <option value="7">台湾居民居住证</option>
                                <option value="8">军官证</option>
                                <option value="9">其他</option>
                            </select>
                        </li>
                        <li>
                            <span class="form_label">证件号码</span>
                            <input type="text" name="number">
                        </li>
                        <li><span class="form_label">证件图片</span>
                            <div class="upload_img">
                                <div><i class="iconfont iconxiangji"></i></div>
                                <p>上传身份证正面</p>
                                <input class="txt" type="hidden" name="image1" id="image1" value="">
                                <img id="img" src="" style="display: none;"><font style="color: #cc3333">请上传JPG格式的图片</font>
                                <input class="txt" type="file" name="file" id="upload-file" onchange="uploadimg()">
                            </div>
                        </li>
                        <li>
                            <span class="form_label">&nbsp;</span>
                            <input type="submit" class="btn btn_primary" id="add_auth" value="添加">
                        </li>
                    </ul>
                </form>
            </div>

        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            var link=  $("#account-certification");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");


            //提交
            $("#form").validate({
                rules: {
                    name: {
                        required: true,
                    },
                    type: {
                        required: true,
                    },
                    number: {
                        required: true,
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
               if ($("#idCardFile").attr('value')===''){
                   layer.msg('请先上传证件',{icon:2,time:2000});
                   return false;
               }
                    $(form).ajaxSubmit({
                        type: 'post',
                        success: function (data) {
                            if (data.msg === 'success') {
                                layer.msg('成功!', {icon: 1, time: 1500}, function () {
                                    window.location = '/account/auth/personal';
                                })
                            } else {
                                layer.msg(data.data.error, {icon: 2, time: 2000,});
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg(XmlHttpRequest.responseJSON.data, {icon: 2, time: 2000}, function () {
                            });
                        }
                    });
                }
            });
        });
        //上传图片
        function uploadimg() {
            $('#form').ajaxSubmit({
                type: "POST",
                url: '/upload',
                dataType: 'json',
                success: function (data) {
                    if (data.code === 200) {
                        $('#image1').val(data.data.url);
                        $('#img').show();
                        $('#img').attr("src","/"+data.data.url);
                        $('#upload-file').remove();
                    } else {
                        layer.msg('上传失败!', {icon: 2, time: 2000,});
                    }
                }
            });
        }
    </script>
    @endsection
